import { formatDate } from '../utils/index'
/**
 * 资源负荷图功能
 */
// 标准时间
function formatDuring(millisecond) {
  const prefixStr = millisecond < 0 ? '前 ' : '',
    days = Math.abs(parseInt(millisecond / (1000 * 60 * 60 * 24))),
    hours = Math.abs(
      parseInt((millisecond % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
    ),
    minutes = Math.abs(
      parseInt((millisecond % (1000 * 60 * 60)) / (1000 * 60))
    ),
    seconds = Math.abs((millisecond % (1000 * 60)) / 1000)
  return (
    prefixStr +
    days +
    ' 天 ' +
    hours +
    ' 时 ' +
    minutes +
    ' 分 ' +
    seconds +
    ' 秒 '
  )
}
export default () => ({
  tree: true,
  scheduleTooltip: false,
  cellTooltip: false,
  cellEdit: false,
  regionResize: true, // 分隔符可以拖动
  eventEdit: false,
  simpleEventEdit: false,
  eventResize: false,
  eventDragCreate: false, // 拖拽添加事件
  eventDragSelect: false,
  timeAxisHeaderMenu: false,
  headerMenu: false, // 左侧列表表头 右键菜单
  headerZoom: false, // 拖动时间轴缩放区域
  stripe: false,
  filterBar: false,
  resourceTimeRanges: true,
  labels: {
    top: null,
    right: null,
    bottom: null,
    /*  bottom: {
      renderer: ({ eventRecord }) => {
        const eventColor = eventRecord?.eventColors ?? '#f6eac9'
        return '<span class="major-gantt-label" style="color:' + eventColor + '">' + eventRecord.name + '</span>'
      }
    }, */
    left: null,
  },
  columnLines: false,
  // criticalPaths: false,
  projectLines: false,
  dependencies: {
    allowCreate: false,
    highlightDependenciesOnEventHover: true,
  },
  eventDrag: false,
  scheduleMenu: {
    items: {
      addEvent: false,
      deleteEvent: false,
      unassignEvent: false,
      editEvent: false,
    },
  },
  cellMenu: false,
  eventMenu: {
    items: {
      addEvent: false,
      deleteEvent: false,
      unassignEvent: false,
      editEvent: false,
    },
  },
  eventTooltip: {
    template: ({ eventRecord }) => {
      console.log(eventRecord.startDate)
      console.log(eventRecord.endDate)
      console.log(eventRecord)
      const startDate = formatDate(eventRecord.startDate)
      const endDate = formatDate(eventRecord.endDate)

      console.log(startDate)
      console.log(endDate)

      return `<div class="gantt-tool-tip">任务名称：${eventRecord.name}</div>
        <div class="gantt-tool-tip">开始时间：${startDate}</div> 
        <div class="gantt-tool-tip">结束时间：${endDate}</div> 
        `
    },
  },
})
